package bo

import (
	"fmt"
	"gitee.com/git_public/vfaith/builtin/bean"
	"gitee.com/git_public/vfaith/builtin/vault"
	"gitee.com/git_public/vfaith/toolkit/generate/model/po"
)

type GenModel struct {
	*bean.DeclareDTO
	GenType     int    `query:"genType"`     //生成类型`
	GenBasePath string `query:"genBasePath"` //根目录
	PageTitle   string `query:"pageTitle"`   //标题
	ModuleName  string `query:"moduleName"`  //模块名
	FileName    string `query:"fileName"`    //文件名
	ClassName   string `query:"className"`   //类名
	TableName   string `query:"tableName"`   //数据表
	ViewName    string `query:"viewName"`    //视图名
	ViewSql     string `query:"viewSql"`     //数据视图
	Columns     []po.Column
	ImportSlice []string
	TableMap    *vault.TableMap
}

func (gm *GenModel) InitDTO() error {
	if gm.GenBasePath == "" {
		gm.GenBasePath = "modules/mortal"
	}

	if gm.PageTitle == "" {
		return fmt.Errorf("pageTitle不能为空")
	}

	if gm.ModuleName == "" {
		return fmt.Errorf("moduleName不能为空")
	}

	if gm.FileName == "" {
		return fmt.Errorf("fileName不能为空")
	}

	if gm.ClassName == "" {
		return fmt.Errorf("className不能为空")
	}

	if gm.GenType == 11 || gm.GenType == 12 || gm.GenType == 13 {
		if gm.TableName == "" {
			return fmt.Errorf("tableName不能为空")
		}
	}

	if gm.GenType == 21 || gm.GenType == 22 {
		if gm.ViewName == "" {
			return fmt.Errorf("ViewName不能为空")
		}
	}

	return nil
}
